<?php
class Country extends AppModel {

	var $name = 'Country';
    var $validate = array(
        'name' =>
            array(
                'length' => array(
                    'rule'    => array('between', 3, 40),
                    'message' => 'Country name must be between 3 and 40 characters long'
                ),
                'unique'   => array(
                    'rule'    => 'isUnique',
                    'message' => 'This country name has already been added'
                )
            ),
        'code' =>
            array(
                '3letters' => array(
                    'rule'    => array('custom', '/[A-Z]{3}$/i'),
                    'message' => 'Please supply 3 capital letters'
                ),
                'unique'   => array(
                    'rule'    => 'isUnique',
                    'message' => 'This code has already been added'
                )
            ),
        'code2' =>
            array(
                '2letters' => array(
                    'rule'    => array('custom', '/[A-Z]{2}$/i'),
                    'message' => 'Please supply 2 capital letters'
                ),
                'unique'   => array(
                    'rule'    => 'isUnique',
                    'message' => 'This code has already been added'
                )
            )
    );
    var $hasOne  = array(
        'Localization' => array('dependent' => true)
    );
    var $hasMany = array(
        'Location' => array('dependent' => true)
    );


    function beforeSave () {
        $this->data['Country']['name']  = ucwords($this->data['Country']['name']);
        $this->data['Country']['code']  = up($this->data['Country']['code']);
        $this->data['Country']['code2'] = up($this->data['Country']['code2']);
        return true;
    } // beforeSave

} // AppModel
?>